<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>审批计划</title>
</head>
<body>
<script type="text/javascript">

	$(function(){
		
		//获取当前登录用户的id
		var  shenpi_staffId = $("#tontyiStaffId").html();
		var shenpi_state  = undefined;
		
		//查找出需要当前用户审批的采购计划
		$("#tb-medPurchPlan-sp").datagrid({
			url: "queryPurPlanByLoginUser_yzr",
			queryParams:{
				page:1, 
    			rows:10,
				staffId: shenpi_staffId
			}
		});
		
		//刷新
		$("#yzr_approval_reload").linkbutton({onClick: function(){
			$("#tb-medPurchPlan-sp").datagrid({
				url: "queryPurPlanByLoginUser_yzr",
				queryParams:{
					page:1, 
	    			rows:10,
					staffId: shenpi_staffId
				}
			});
		}});
		
		//查看计划-审核
		$("#yzr_test").linkbutton({onClick: function(){
			var rows = $("#tb-medPurchPlan-sp").datagrid("getSelections");
			if(rows.length == 1){
				$('#yzr-purchDet-sp-window').window({'title': "审核采购计划"});
				$('#yzr-purchDet-sp-window').window("open");
				var purchId = rows[0].purchId;
				
				$.getJSON("queryMedPurchById", {"purchId": purchId}, function(data){
					$("#yzr-purchDet-cgbh-sp").linkbutton({text: data.purchId});
					$("#yzr-purchDet-xmmc-sp").linkbutton({text: data.purchTitle});
					$("#yzr-purchDet-zdr-sp").linkbutton({text: data.staffName});
					$("#yzr-purchDet-zdsj-sp").linkbutton({text: data.purchZdTime});
					$("#yzr-purchDet-spr-sp").linkbutton({text: data.staffNameSp});
					$("#yzr-purchDet-spzt-sp").linkbutton({text: data.purchAutditState});
					
					if(data.purchAutditState=='待审核' || data.purchAutditState=='未通过'){
						$("#yzr-purchDet-spzt-sp").css({'color': 'red'});
					}
					if(data.purchAutditState=='已通过'){
						$("#yzr-purchDet-spzt-sp").css({'color': 'green'});
					}
					$("#yzr-purchDet-spsj-sp").linkbutton({text: data.purchAutditTime});
					
					$("#yzr-purchDet-cgzt-sp").linkbutton({text: data.purchState});
					
					if(data.purchState=='未采购'){
						$("#yzr-purchDet-cgzt-sp").css({'color': 'red'});
					}
				});	
				
				 //根据id查看详情	
				 $("#yzr-purchDet-sp-dg").datagrid({
					url:'queryAllPurchDet',
					width: '100%',
					queryParams:{
						page:1, 
		    			rows:100,
						purchId: purchId
					}
				});
			}else{
				$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
			}
		}});
		
		
		//通过
		$("#yzr-sp-pass").linkbutton({onClick: function(){
			
			$.messager.prompt("提示", "备注", function (data) {
	            if (data) {         	
	            	shenpi_state = '已通过';
	            	
	            	var rows = $("#tb-medPurchPlan-sp").datagrid("getSelections");
	            	var planId_sp = rows[0].purchId;
					
					
	            	$("#yzr_purchDet_sp_form").form("submit", {
	        			url: 'approvalPlan_yzr',
	        			queryParams:{
	        				shenpiState: shenpi_state,
	        				remark: data,
	        				planId: planId_sp
						},
	        			success: function(v){
	        				$.messager.alert('提示', "审批成功");
	        				$('#yzr-purchDet-sp-window').window("close");
	        				$("#tb-medPurchPlan-sp").datagrid("reload");
	        			}
	        		});
	           }
			});
			
		}});
		
		//不通过
		$("#yzr-sp-fail").linkbutton({onClick: function(){					
			$.messager.prompt("提示", "备注", function (data) {
	            if (data) {
	            	shenpi_state = '未通过';
	            	var rows = $("#tb-medPurchPlan-sp").datagrid("getSelections");
	            	var planId_sp = rows[0].purchId;
					
					
	            	$("#yzr_purchDet_sp_form").form("submit", {
	        			url: 'approvalPlan_yzr',
	        			queryParams:{
	        				shenpiState: shenpi_state,
	        				remark: data,
	        				planId: planId_sp
						},
	        			success: function(v){
	        				$.messager.alert('提示', "审批成功");
	        				$('#yzr-purchDet-sp-window').window("close");
	        				$("#tb-medPurchPlan-sp").datagrid("reload");
	        			}
	        		});
	           }
			});
					
		}});
		
	});
</script>


	<!-- 显示所有计划 -->
	<table id="tb-medPurchPlan-sp" class="easyui-datagrid" 
		data-options="
			singleSelect: true,
			fitColumns:true,
			fit:true,
			striped:true,
			pagination: true,
			pageSize: 16,
			pageList: [16, 32, 48, 54],
			rownumbers: true,
			toolbar: '#yzr-approval-tb',
			border:false
			">
		<thead>
			<tr>	
				<th data-options="field:'purchId',width:'10%',checkbox:true,align:'center'">计划编号</th>				
				<th data-options="field:'purchTitle',width:'17%',align:'center'">项目名称</th>
				<th data-options="field:'staffName',width:'11%',align:'center'">制定人</th>
				<th data-options="field:'staffNameSp',width:'11%',align:'center'">审批人</th>				
				<th data-options="field:'purchZdTime',width:'16%',align:'center'">制定时间</th>				
				<th data-options="field:'purchAutditState',width:'16%',align:'center'">审批状态</th>				
				<th data-options="field:'purchArriivalDate',width:'16%',align:'center'">预计到货时间</th>
				<th data-options="field:'purchState',width:'11%',align:'center'">采购状态</th>
			</tr>
		</thead>
	</table>
	
	<!-- 工具栏 -->
	<div id="yzr-approval-tb">
		<a id="yzr_test" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">审批计划</a>
		<a id="yzr_approval_reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>					
	</div>
	
	
	<!--查看详情窗口 审批-->
	<div id="yzr-purchDet-sp-window" class="easyui-window" title="采购计划详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:70%;height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div  data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">			
				<form id="yzr_purchDet_sp_form" method="post">
					<table width="100%">
						<tr>
							<td>采购计划编号:<a id="yzr-purchDet-cgbh-sp" name="purchId" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>项目名称:<a id="yzr-purchDet-xmmc-sp" name="purchTitle" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定人:<a id="yzr-purchDet-zdr-sp" name="staffName" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>制定时间:<a id="yzr-purchDet-zdsj-sp" name="purchZdTime" class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
						<tr>
							<td>审批人:<a id="yzr-purchDet-spr-sp" name="staffNameSp" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批状态:<a id="yzr-purchDet-spzt-sp" name="purchAutditState" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>审批时间:<a id="yzr-purchDet-spsj-sp" name="purchAutditTime" class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>采购状态:<a id="yzr-purchDet-cgzt-sp" name="purchState" class="easyui-linkbutton" data-options="plain:true"></a></td>
						</tr>
					</table>
						
					<div style="margin: 5px;">
						<div id="yzr-purchDet-sp-tabs" class="easyui-tabs" style="width:100%; margin-top:10px;" 
							data-options="plain:true,narrow:true">
							
							<div title="采购计划明细" style="padding:10px;">
								<table id="yzr-purchDet-sp-dg" class="easyui-datagrid" 
										data-options="
											iconCls: 'icon-edit',
											singleSelect: true,										
											width: '100%'
											">
										<thead>
											<tr>	
												<th data-options="field:'purchDetId',width:'20%',align:'center'">计划明细编号</th>	
												<!-- <th data-options="field:'medId',width:'16%',align:'center'">药品编号</th>	 -->		
												<th data-options="field:'medName',width:'20%',align:'center'">药品名称</th>
												<th data-options="field:'purchDetGuige',width:'10%',align:'center'">规格</th>
												<th data-options="field:'purchDetUnit',width:'10%',align:'center'">单位</th>
												<th data-options="field:'purchDetNumber',width:'10%',align:'center'">数量</th>
												<th data-options="field:'supName',width:'20%',align:'center'">供应商</th>
												<th data-options="field:'purchDetYijiMoney',width:'11%',align:'center'">预计金额</th>
											</tr>
										</thead>
								 </table>
							</div>							
						</div>						
					</div>
				</form>				
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<div style="display:inline;"><a id="yzr-sp-pass" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true">PASS</a></div>
				<a id="yzr-sp-fail" class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true">FAIL</a>
			</div>			
		</div>
	</div>
</body>
</html>